package com.xbongbong.parent.parse.data;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.AnalysisDataDTO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.parse.data.FormDataGetAnalysisDataHelp;
import com.xbongbong.saas.help.FormDataAnalysisHelp;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * 关联数据解析(保持原有格式)
 *
 * @author LiZhikang
 * @date 2022/8/11 11:00
 */
@Component
public class FormDataLinkDataAnalysisDataHelp extends FormDataGetAnalysisDataHelp {

    @Resource
    private FormDataAnalysisHelp formDataAnalysisHelp;

    @Override
    public void analysisData(AnalysisDataDTO analysisDataDTO, JSONObject resultJsonObject, Map<String, Object> linkData
            , Set<Object> linkDataSet) throws XbbException {
        // TODO 关于成员和部门回显需要去掉离职人员，现在直接不限，具体如何显示，未解决
        FieldAttrEntity fieldAttrEntity = analysisDataDTO.getFieldAttrEntity();
        JSONObject objectJsonObject = analysisDataDTO.getDataJsonObject();

        if (FieldTypeEnum.RADIO_GROUP.getType().equals(fieldAttrEntity.getFieldType()) || FieldTypeEnum.COMBO.getType().equals(fieldAttrEntity.getFieldType())) {
            formDataAnalysisHelp.analysisCombo(objectJsonObject, resultJsonObject, fieldAttrEntity, analysisDataDTO.getCorpid());
        } else if (Objects.equals(FieldTypeEnum.STAGE_THRUSTER.getType(), fieldAttrEntity.getFieldType())) {
            formDataAnalysisHelp.analysisListStageJsonObject(resultJsonObject, analysisDataDTO);
        } else if (FieldTypeEnum.CHECKBOX_GROUP.getType().equals(fieldAttrEntity.getFieldType())
                || FieldTypeEnum.COMBO_CHECK.getType().equals(fieldAttrEntity.getFieldType())) {
            // 多选转化成逗号隔开的字符串
            formDataAnalysisHelp.analysisComboReturnStr(objectJsonObject, resultJsonObject, fieldAttrEntity);
        } else {
            super.analysisData(analysisDataDTO, resultJsonObject, linkData, linkDataSet);
        }

    }
}
